﻿/*
 *  DFUtil - a utility for creating and implementing blueprints in Dwarf Fortress.
 *  
 *  Copyright (C) 2009  Katharine Gillis
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/.
*/

using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace DFUtil
{
    /// <summary>
    /// Abstract class that handles the basics of a graphic for the grid.
    /// </summary>
    public abstract class Graphic
    {
        #region Variables
        protected Tileset _tileset;
        #endregion

        #region Properties

        protected Point _point;
        /// <summary>
        /// Gets the top left corner of the graphic, in grid points.
        /// </summary>
        /// <returns>Point for top left corner.</returns>
        public Point Point
        {
            get { return _point; }
        }

        protected Size _size;
        /// <summary>
        /// Gets the size of the graphic, in grid points.
        /// </summary>
        /// <returns>Size of graphic.</returns>
        public Size Size
        {
            get { return _size; }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Creates the basic graphic object, storing the point and size.
        /// </summary>
        /// <param name="point">Top left corner of the graphic.</param>
        /// <param name="size">Size of the graphic.</param>
        protected Graphic(Point point, Size size)
        {
            _point = point;
            _size = size;
            _tileset = new Tileset();
        }

        #endregion

        #region Abstract members

        public abstract Bitmap GetBitmap();

        #endregion
    }

    public class DesignationGraphic : Graphic
    {
        #region Variables
        private int _tileRow = 0;
        private int _tileColumn = 0;
        #endregion

        #region Constructor
        public DesignationGraphic(Point point, Size size, int tileRow, int tileColumn) : base(point, size)
        {
            _tileRow = tileRow;
            _tileColumn = tileColumn;
        }
        #endregion

        #region Factory Method

        public static DesignationGraphic Create(Point point, Size size, Designation type)
        {
            switch (type)
            {
                case Designation.Mine:
                    return new DesignationGraphic(point, size, 14, 2);
                case Designation.Channel:
                    return new DesignationGraphic(point, size, 10, 15);
                case Designation.UpStaircase:
                    return new DesignationGraphic(point, size, 12, 3);
                case Designation.DownStaircase:
                    return new DesignationGraphic(point, size, 14, 3);
                case Designation.UpDownStaircase:
                    return new DesignationGraphic(point, size, 8, 5);
                default:
                    throw new ArgumentException("Invalid Designation type.");
            }
        }

        #endregion

        #region Members

        public Bitmap GetBorderBitmap()
        {
            Bitmap bitmap = new Bitmap((_size.Width + 2) * _tileset.GridWidth, (_size.Height + 2) * _tileset.GridHeight);

            Bitmap tile = new Bitmap(_tileset.GridWidth, _tileset.GridHeight);
            ColorMap[] colourMap = new ColorMap[2];
            colourMap[0] = new ColorMap();
            colourMap[0].OldColor = Color.Magenta;
            colourMap[0].NewColor = Color.Silver;
            colourMap[1] = new ColorMap();
            colourMap[1].OldColor = Color.White;
            colourMap[1].NewColor = Color.Gray;
            ImageAttributes attrs = new ImageAttributes();
            attrs.SetRemapTable(colourMap);
            Graphics gTile = Graphics.FromImage(tile);
            gTile.DrawImage(_tileset.Bitmap, new Rectangle(0, 0, _tileset.GridWidth, _tileset.GridHeight), 3 * _tileset.GridWidth, 2 * _tileset.GridHeight, _tileset.GridWidth, _tileset.GridHeight, GraphicsUnit.Pixel, attrs);

            Graphics gBitmap = Graphics.FromImage(bitmap);
            for (int x = 0; x < (_size.Width + 2); x++)
            {
                gBitmap.DrawImage(tile, new Point(x * _tileset.GridWidth, 0));
                gBitmap.DrawImage(tile, new Point(x * _tileset.GridWidth, (_size.Height + 1) * _tileset.GridHeight));
            }
            for (int y = 1; y <= (_size.Height); y++)
            {
                gBitmap.DrawImage(tile, new Point(0, y * _tileset.GridHeight));
                gBitmap.DrawImage(tile, new Point((_size.Width + 1) * _tileset.GridWidth, y * _tileset.GridHeight));
            }
            return bitmap;
        }
        #endregion

        #region Graphic Members
        public override Bitmap GetBitmap()
        {
            Bitmap bitmap = new Bitmap(_size.Width * _tileset.GridWidth, _size.Height * _tileset.GridHeight);

            Bitmap tile = new Bitmap(_tileset.GridWidth, _tileset.GridHeight);
            ColorMap[] colourMap = new ColorMap[2];
            colourMap[0] = new ColorMap();
            colourMap[0].OldColor = Color.Magenta;
            colourMap[0].NewColor = Color.Black;
            colourMap[1] = new ColorMap();
            colourMap[1].OldColor = Color.White;
            colourMap[1].NewColor = Color.Gray;
            ImageAttributes attrs = new ImageAttributes();
            attrs.SetRemapTable(colourMap);
            Graphics gTile = Graphics.FromImage(tile);
            gTile.DrawImage(_tileset.Bitmap, new Rectangle(0, 0, _tileset.GridWidth, _tileset.GridHeight), _tileRow * _tileset.GridWidth, _tileColumn * _tileset.GridHeight, _tileset.GridWidth, _tileset.GridHeight, GraphicsUnit.Pixel, attrs);

            Graphics gBitmap = Graphics.FromImage(bitmap);
            for (int y = 0; y < _size.Height; y++)
            {
                for (int x = 0; x < _size.Width; x++)
                {
                    gBitmap.DrawImage(tile, new Point(x * _tileset.GridWidth, y * _tileset.GridHeight));
                }
            }

            return bitmap;

        }
        #endregion
    }

    public class BuildingGraphic : Graphic
    {
        #region Variables
        private Point[,] _tiles;
        private ColorMap[,] _colours;
        #endregion

        #region Constructor

        public BuildingGraphic(Point point, Size size, Point[,] tiles, ColorMap[,] colours) : base(point, size)
        {
            _tiles = tiles;
            _colours = colours;
        }

        #endregion

        #region Factory Method

        public static BuildingGraphic Create(Point point, Building type)
        {
            Point[,] tiles;
            ColorMap[,] colours;
            switch (type)
            {
                case Building.Bed:
                    return new BuildingGraphic(point, new Size(1, 1), GetBedTiles(), GetBedColours());
                case Building.Chair:
                    return new BuildingGraphic(point, new Size(1, 1), GetChairTiles(), GetChairColours());
                case Building.Table:
                    return new BuildingGraphic(point, new Size(1, 1), GetTableTiles(), GetTableColours());
                case Building.Door:
                    return new BuildingGraphic(point, new Size(1, 1), GetDoorTiles(), GetDoorColours());
                case Building.Lever:
                    return new BuildingGraphic(point, new Size(1, 1), GetLeverTiles(), GetLeverColours());
                case Building.StonefallTrap:
                    return new BuildingGraphic(point, new Size(1, 1), GetStonefallTrapTiles(), GetStonefallTrapColours());
                case Building.WeaponTrap:
                    return new BuildingGraphic(point, new Size(1, 1), GetWeaponTrapTiles(), GetWeaponTrapColours());
                case Building.CageTrap:
                    return new BuildingGraphic(point, new Size(1, 1), GetCageTrapTiles(), GetCageTrapColours());
                case Building.Container:
                    return new BuildingGraphic(point, new Size(1, 1), GetContainerTiles(), GetContainerColours());
                case Building.Cabinet:
                    return new BuildingGraphic(point, new Size(1, 1), GetCabinetTiles(), GetCabinetColours());
                case Building.CarpentersWorkshop:
                    return new BuildingGraphic(point, new Size(3, 3), GetCarpentersWorkshopTiles(), GetCarpentersWorkshopColours());
                case Building.MasonsWorkshop:
                    return new BuildingGraphic(point, new Size(3, 3), GetMasonsWorkshopTiles(), GetMasonsWorkshopColours());
                case Building.CraftdwarfsWorkshop:
                    return new BuildingGraphic(point, new Size(3, 3), GetCraftdwarfsWorkshopTiles(), GetCraftdwarfsWorkshopColours());
                case Building.BowyersWorkshop:
                    return new BuildingGraphic(point, new Size(3, 3), GetBowyersWorkshopTiles(), GetBowyersWorkshopColours());
                case Building.ButchersShop:
                    return new BuildingGraphic(point, new Size(3, 3), GetButchersShopTiles(), GetButchersShopColours());
                case Building.Fishery:
                    return new BuildingGraphic(point, new Size(3, 3), GetFisheryTiles(), GetFisheryColours());
                case Building.FarmersWorkshop:
                    return new BuildingGraphic(point, new Size(3, 3), GetFarmersWorkshopTiles(), GetFarmersWorkshopColours());
                case Building.Loom:
                    return new BuildingGraphic(point, new Size(3, 3), GetLoomTiles(), GetLoomColours());
                case Building.Still:
                    return new BuildingGraphic(point, new Size(3, 3), GetStillTiles(), GetStillColours());
                case Building.MechanicsWorkshop:
                    return new BuildingGraphic(point, new Size(3, 3), GetMechanicsWorkshopTiles(), GetMechanicsWorkshopColours());
                case Building.TradeDepot:
                    return new BuildingGraphic(point, new Size(5, 5), GetTradeDepotTiles(), GetTradeDepotColours());
                case Building.Kennels:
                    return new BuildingGraphic(point, new Size(5, 5), GetKennelsTiles(), GetKennelsColours());
                default:
                    throw new ArgumentException("Bad Building type.");
            }
        }

        #endregion

        #region Graphic members
        public override Bitmap GetBitmap()
        {
            Bitmap bitmap = new Bitmap(_tileset.GridWidth * _size.Width, _tileset.GridHeight * _size.Height);
            Graphics g = Graphics.FromImage(bitmap);

            for (int y = 0; y < _size.Height; y++)
            {
                for (int x = 0; x < _size.Width; x++)
                {
                    ColorMap[] colourMap = new ColorMap[2];
                    colourMap[0] = new ColorMap();
                    colourMap[0].OldColor = Color.Magenta;
                    colourMap[0].NewColor = _colours[y, x].NewColor;
                    colourMap[1] = new ColorMap();
                    colourMap[1].OldColor = Color.White;
                    colourMap[1].NewColor = _colours[y, x].OldColor;
                    ImageAttributes attrs = new ImageAttributes();
                    attrs.SetRemapTable(colourMap);
                    g.DrawImage(_tileset.Bitmap, new Rectangle(x * _tileset.GridWidth, y * _tileset.GridHeight, _tileset.GridWidth, _tileset.GridHeight), _tiles[y, x].X * _tileset.GridWidth, _tiles[y, x].Y * _tileset.GridHeight, _tileset.GridWidth, _tileset.GridHeight, GraphicsUnit.Pixel, attrs);
                }
            }

            return bitmap;
        }
        #endregion

        #region Private members

        private static Point[,] GetBedTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(9, 14);
            return tiles;
        }

        private static ColorMap[,] GetBedColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Olive;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetChairTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(2, 13);
            return tiles;
        }

        private static ColorMap[,] GetChairColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetTableTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(1, 13);
            return tiles;
        }

        private static ColorMap[,] GetTableColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetDoorTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(5, 12);
            return tiles;
        }

        private static ColorMap[,] GetDoorColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Silver;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetLeverTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(5, 9);
            return tiles;
        }

        private static ColorMap[,] GetLeverColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetStonefallTrapTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(14, 5);
            return tiles;
        }

        private static ColorMap[,] GetStonefallTrapColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.White;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetWeaponTrapTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(14, 5);
            return tiles;
        }

        private static ColorMap[,] GetWeaponTrapColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Red;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetCageTrapTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(14, 5);
            return tiles;
        }

        private static ColorMap[,] GetCageTrapColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Lime;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetContainerTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(2, 9);
            return tiles;
        }

        private static ColorMap[,] GetContainerColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point [,] GetCabinetTiles()
        {
            Point[,] tiles = new Point[1, 1];
            tiles[0, 0] = new Point(3, 14);
            return tiles;
        }

        private static ColorMap[,] GetCabinetColours()
        {
            ColorMap[,] colours = new ColorMap[1, 1];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetCarpentersWorkshopTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(14, 2);
            tiles[0, 1] = new Point(2, 2);
            tiles[0, 2] = new Point(13, 3);
            tiles[1, 0] = new Point(0, 11);
            tiles[1, 1] = new Point(14, 2);
            tiles[1, 2] = new Point(14, 2);
            tiles[2, 0] = new Point(0, 11);
            tiles[2, 1] = new Point(13, 5);
            tiles[2, 2] = new Point(0, 11);
            return tiles;
        }

        private static ColorMap[,] GetCarpentersWorkshopColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Silver;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Olive;
            colours[0, 2].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Gray;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Gray;
            colours[1, 2].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Gray;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Gray;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Gray;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetMasonsWorkshopTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(11, 3);
            tiles[0, 1] = new Point(14, 2);
            tiles[0, 2] = new Point(0, 11);
            tiles[1, 0] = new Point(0, 11);
            tiles[1, 1] = new Point(11, 5);
            tiles[1, 2] = new Point(0, 11);
            tiles[2, 0] = new Point(14, 2);
            tiles[2, 1] = new Point(15, 6);
            tiles[2, 2] = new Point(14, 2);
            return tiles;
        }

        private static ColorMap[,] GetMasonsWorkshopColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.White;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Gray;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Gray;
            colours[0, 2].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Gray;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Gray;
            colours[1, 2].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Gray;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Silver;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Gray;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetCraftdwarfsWorkshopTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(14, 2);
            tiles[0, 1] = new Point(13, 2);
            tiles[0, 2] = new Point(0, 11);
            tiles[1, 0] = new Point(0, 11);
            tiles[1, 1] = new Point(13, 5);
            tiles[1, 2] = new Point(14, 2);
            tiles[2, 0] = new Point(0, 11);
            tiles[2, 1] = new Point(0, 11);
            tiles[2, 2] = new Point(14, 2);
            return tiles;
        }

        private static ColorMap[,] GetCraftdwarfsWorkshopColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.White;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Gray;
            colours[0, 2].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Gray;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Gray;
            colours[1, 2].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Gray;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Gray;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Gray;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetBowyersWorkshopTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(0, 11);
            tiles[0, 1] = new Point(14, 14);
            tiles[0, 2] = new Point(14, 2);
            tiles[1, 0] = new Point(0, 11);
            tiles[1, 1] = new Point(13, 5);
            tiles[1, 2] = new Point(14, 2);
            tiles[2, 0] = new Point(0, 11);
            tiles[2, 1] = new Point(14, 2);
            tiles[2, 2] = new Point(8, 2);
            return tiles;
        }

        private static ColorMap[,] GetBowyersWorkshopColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Olive;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Gray;
            colours[0, 2].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Gray;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Gray;
            colours[1, 2].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Gray;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Gray;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Olive;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetButchersShopTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(14, 2);
            tiles[0, 1] = new Point(14, 2);
            tiles[0, 2] = new Point(2, 11);
            tiles[1, 0] = new Point(7, 15);
            tiles[1, 1] = new Point(14, 2);
            tiles[1, 2] = new Point(12, 14);
            tiles[2, 0] = new Point(14, 2);
            tiles[2, 1] = new Point(14, 2);
            tiles[2, 2] = new Point(14, 2);
            return tiles;
        }

        private static ColorMap[,] GetButchersShopColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Gray;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Gray;
            colours[0, 2].NewColor = Color.Maroon;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Maroon;
            colours[1, 0].NewColor = Color.Silver;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Maroon;
            colours[1, 2].NewColor = Color.Silver;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Gray;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Gray;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Gray;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetFisheryTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(2, 11);
            tiles[0, 1] = new Point(0, 14);
            tiles[0, 2] = new Point(3, 2);
            tiles[1, 0] = new Point(14, 2);
            tiles[1, 1] = new Point(14, 2);
            tiles[1, 2] = new Point(14, 2);
            tiles[2, 0] = new Point(14, 2);
            tiles[2, 1] = new Point(2, 11);
            tiles[2, 2] = new Point(14, 2);
            return tiles;
        }

        private static ColorMap[,] GetFisheryColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Silver;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.White;
            colours[0, 1].NewColor = Color.Silver;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Silver;
            colours[0, 2].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Gray;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Gray;
            colours[1, 2].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Gray;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Gray;
            colours[2, 1].NewColor = Color.Silver;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Gray;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetFarmersWorkshopTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(14, 2);
            tiles[0, 1] = new Point(1, 4);
            tiles[0, 2] = new Point(0, 15);
            tiles[1, 0] = new Point(14, 2);
            tiles[1, 1] = new Point(14, 2);
            tiles[1, 2] = new Point(14, 2);
            tiles[2, 0] = new Point(15, 4);
            tiles[2, 1] = new Point(2, 13);
            tiles[2, 2] = new Point(13, 14);
            return tiles;
        }

        private static ColorMap[,] GetFarmersWorkshopColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Silver;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Yellow;
            colours[0, 2].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Gray;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Gray;
            colours[1, 2].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Silver;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Silver;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Aqua;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetLoomTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(3, 12);
            tiles[0, 1] = new Point(3, 2);
            tiles[0, 2] = new Point(4, 11);
            tiles[1, 0] = new Point(13, 14);
            tiles[1, 1] = new Point(14, 2);
            tiles[1, 2] = new Point(14, 2);
            tiles[2, 0] = new Point(13, 14);
            tiles[2, 1] = new Point(14, 2);
            tiles[2, 2] = new Point(7, 10);
            return tiles;
        }

        private static ColorMap[,] GetLoomColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Gray;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Gray;
            colours[0, 2].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Magenta;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Gray;
            colours[1, 2].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Silver;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Gray;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Red;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetStillTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(6, 15);
            tiles[0, 1] = new Point(13, 12);
            tiles[0, 2] = new Point(8, 11);
            tiles[1, 0] = new Point(15, 6);
            tiles[1, 1] = new Point(14, 2);
            tiles[1, 2] = new Point(14, 7);
            tiles[2, 0] = new Point(1, 11);
            tiles[2, 1] = new Point(14, 2);
            tiles[2, 2] = new Point(15, 6);
            return tiles;
        }

        private static ColorMap[,] GetStillColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Black;
            colours[0, 0].NewColor = Color.Silver;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Gray;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Gray;
            colours[0, 2].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Silver;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Green;
            colours[1, 2].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Gray;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Gray;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Silver;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetMechanicsWorkshopTiles()
        {
            Point[,] tiles = new Point[3, 3];
            tiles[0, 0] = new Point(0, 8);
            tiles[0, 1] = new Point(14, 2);
            tiles[0, 2] = new Point(14, 2);
            tiles[1, 0] = new Point(14, 2);
            tiles[1, 1] = new Point(11, 5);
            tiles[1, 2] = new Point(1, 11);
            tiles[2, 0] = new Point(14, 2);
            tiles[2, 1] = new Point(14, 5);
            tiles[2, 2] = new Point(15, 7);
            return tiles;
        }

        private static ColorMap[,] GetMechanicsWorkshopColours()
        {
            ColorMap[,] colours = new ColorMap[3, 3];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Gray;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Gray;
            colours[0, 2].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Gray;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Gray;
            colours[1, 2].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Gray;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Aqua;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.White;
            colours[2, 2].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetTradeDepotTiles()
        {
            Point[,] tiles = new Point[5, 5];
            tiles[0, 0] = new Point(15, 4);
            tiles[0, 1] = new Point(0, 0);
            tiles[0, 2] = new Point(0, 0);
            tiles[0, 3] = new Point(0, 0);
            tiles[0, 4] = new Point(15, 4);
            tiles[1, 0] = new Point(0, 0);
            tiles[1, 1] = new Point(0, 0);
            tiles[1, 2] = new Point(0, 0);
            tiles[1, 3] = new Point(0, 0);
            tiles[1, 4] = new Point(0, 0);
            tiles[2, 0] = new Point(0, 0);
            tiles[2, 1] = new Point(0, 0);
            tiles[2, 2] = new Point(15, 4);
            tiles[2, 3] = new Point(0, 0);
            tiles[2, 4] = new Point(0, 0);
            tiles[3, 0] = new Point(0, 0);
            tiles[3, 1] = new Point(0, 0);
            tiles[3, 2] = new Point(0, 0);
            tiles[3, 3] = new Point(0, 0);
            tiles[3, 4] = new Point(0, 0);
            tiles[4, 0] = new Point(15, 4);
            tiles[4, 1] = new Point(0, 0);
            tiles[4, 2] = new Point(0, 0);
            tiles[4, 3] = new Point(0, 0);
            tiles[4, 4] = new Point(15, 4);
            return tiles;
        }

        private static ColorMap[,] GetTradeDepotColours()
        {
            ColorMap[,] colours = new ColorMap[5, 5];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Black;
            colours[0, 1].NewColor = Color.Gray;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Black;
            colours[0, 2].NewColor = Color.Gray;
            colours[0, 3] = new ColorMap();
            colours[0, 3].OldColor = Color.Black;
            colours[0, 3].NewColor = Color.Gray;
            colours[0, 4] = new ColorMap();
            colours[0, 4].OldColor = Color.Gray;
            colours[0, 4].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Black;
            colours[1, 0].NewColor = Color.Gray;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Black;
            colours[1, 1].NewColor = Color.Gray;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Black;
            colours[1, 2].NewColor = Color.Gray;
            colours[1, 3] = new ColorMap();
            colours[1, 3].OldColor = Color.Black;
            colours[1, 3].NewColor = Color.Gray;
            colours[1, 4] = new ColorMap();
            colours[1, 4].OldColor = Color.Black;
            colours[1, 4].NewColor = Color.Gray;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Black;
            colours[2, 0].NewColor = Color.Gray;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Black;
            colours[2, 1].NewColor = Color.Gray;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Gray;
            colours[2, 2].NewColor = Color.Black;
            colours[2, 3] = new ColorMap();
            colours[2, 3].OldColor = Color.Black;
            colours[2, 3].NewColor = Color.Gray;
            colours[2, 4] = new ColorMap();
            colours[2, 4].OldColor = Color.Black;
            colours[2, 4].NewColor = Color.Gray;
            colours[3, 0] = new ColorMap();
            colours[3, 0].OldColor = Color.Black;
            colours[3, 0].NewColor = Color.Gray;
            colours[3, 1] = new ColorMap();
            colours[3, 1].OldColor = Color.Black;
            colours[3, 1].NewColor = Color.Gray;
            colours[3, 2] = new ColorMap();
            colours[3, 2].OldColor = Color.Black;
            colours[3, 2].NewColor = Color.Gray;
            colours[3, 3] = new ColorMap();
            colours[3, 3].OldColor = Color.Black;
            colours[3, 3].NewColor = Color.Gray;
            colours[3, 4] = new ColorMap();
            colours[3, 4].OldColor = Color.Black;
            colours[3, 4].NewColor = Color.Gray;
            colours[4, 0] = new ColorMap();
            colours[4, 0].OldColor = Color.Gray;
            colours[4, 0].NewColor = Color.Black;
            colours[4, 1] = new ColorMap();
            colours[4, 1].OldColor = Color.Black;
            colours[4, 1].NewColor = Color.Gray;
            colours[4, 2] = new ColorMap();
            colours[4, 2].OldColor = Color.Black;
            colours[4, 2].NewColor = Color.Gray;
            colours[4, 3] = new ColorMap();
            colours[4, 3].OldColor = Color.Black;
            colours[4, 3].NewColor = Color.Gray;
            colours[4, 4] = new ColorMap();
            colours[4, 4].OldColor = Color.Gray;
            colours[4, 4].NewColor = Color.Black;
            return colours;
        }

        private static Point[,] GetKennelsTiles()
        {
            Point[,] tiles = new Point[5, 5];
            tiles[0, 0] = new Point(14, 2);
            tiles[0, 1] = new Point(11, 14);
            tiles[0, 2] = new Point(14, 2);
            tiles[0, 3] = new Point(14, 2);
            tiles[0, 4] = new Point(14, 2);
            tiles[1, 0] = new Point(14, 2);
            tiles[1, 1] = new Point(3, 2);
            tiles[1, 2] = new Point(14, 2);
            tiles[1, 3] = new Point(3, 2);
            tiles[1, 4] = new Point(14, 2);
            tiles[2, 0] = new Point(14, 2);
            tiles[2, 1] = new Point(14, 2);
            tiles[2, 2] = new Point(14, 2);
            tiles[2, 3] = new Point(11, 14);
            tiles[2, 4] = new Point(14, 2);
            tiles[3, 0] = new Point(14, 2);
            tiles[3, 1] = new Point(3, 2);
            tiles[3, 2] = new Point(14, 2);
            tiles[3, 3] = new Point(3, 2);
            tiles[3, 4] = new Point(14, 2);
            tiles[4, 0] = new Point(14, 2);
            tiles[4, 1] = new Point(14, 2);
            tiles[4, 2] = new Point(14, 2);
            tiles[4, 3] = new Point(14, 2);
            tiles[4, 4] = new Point(14, 2);
            return tiles;
        }

        private static ColorMap[,] GetKennelsColours()
        {
            ColorMap[,] colours = new ColorMap[5, 5];
            colours[0, 0] = new ColorMap();
            colours[0, 0].OldColor = Color.Gray;
            colours[0, 0].NewColor = Color.Black;
            colours[0, 1] = new ColorMap();
            colours[0, 1].OldColor = Color.Yellow;
            colours[0, 1].NewColor = Color.Black;
            colours[0, 2] = new ColorMap();
            colours[0, 2].OldColor = Color.Gray;
            colours[0, 2].NewColor = Color.Black;
            colours[0, 3] = new ColorMap();
            colours[0, 3].OldColor = Color.Gray;
            colours[0, 3].NewColor = Color.Black;
            colours[0, 4] = new ColorMap();
            colours[0, 4].OldColor = Color.Gray;
            colours[0, 4].NewColor = Color.Black;
            colours[1, 0] = new ColorMap();
            colours[1, 0].OldColor = Color.Gray;
            colours[1, 0].NewColor = Color.Black;
            colours[1, 1] = new ColorMap();
            colours[1, 1].OldColor = Color.Gray;
            colours[1, 1].NewColor = Color.Black;
            colours[1, 2] = new ColorMap();
            colours[1, 2].OldColor = Color.Gray;
            colours[1, 2].NewColor = Color.Black;
            colours[1, 3] = new ColorMap();
            colours[1, 3].OldColor = Color.Gray;
            colours[1, 3].NewColor = Color.Black;
            colours[1, 4] = new ColorMap();
            colours[1, 4].OldColor = Color.Gray;
            colours[1, 4].NewColor = Color.Black;
            colours[2, 0] = new ColorMap();
            colours[2, 0].OldColor = Color.Gray;
            colours[2, 0].NewColor = Color.Black;
            colours[2, 1] = new ColorMap();
            colours[2, 1].OldColor = Color.Gray;
            colours[2, 1].NewColor = Color.Black;
            colours[2, 2] = new ColorMap();
            colours[2, 2].OldColor = Color.Gray;
            colours[2, 2].NewColor = Color.Black;
            colours[2, 3] = new ColorMap();
            colours[2, 3].OldColor = Color.Yellow;
            colours[2, 3].NewColor = Color.Black;
            colours[2, 4] = new ColorMap();
            colours[2, 4].OldColor = Color.Gray;
            colours[2, 4].NewColor = Color.Black;
            colours[3, 0] = new ColorMap();
            colours[3, 0].OldColor = Color.Gray;
            colours[3, 0].NewColor = Color.Black;
            colours[3, 1] = new ColorMap();
            colours[3, 1].OldColor = Color.Gray;
            colours[3, 1].NewColor = Color.Black;
            colours[3, 2] = new ColorMap();
            colours[3, 2].OldColor = Color.Gray;
            colours[3, 2].NewColor = Color.Black;
            colours[3, 3] = new ColorMap();
            colours[3, 3].OldColor = Color.Gray;
            colours[3, 3].NewColor = Color.Black;
            colours[3, 4] = new ColorMap();
            colours[3, 4].OldColor = Color.Gray;
            colours[3, 4].NewColor = Color.Black;
            colours[4, 0] = new ColorMap();
            colours[4, 0].OldColor = Color.Gray;
            colours[4, 0].NewColor = Color.Black;
            colours[4, 1] = new ColorMap();
            colours[4, 1].OldColor = Color.Gray;
            colours[4, 1].NewColor = Color.Black;
            colours[4, 2] = new ColorMap();
            colours[4, 2].OldColor = Color.Gray;
            colours[4, 2].NewColor = Color.Black;
            colours[4, 3] = new ColorMap();
            colours[4, 3].OldColor = Color.Gray;
            colours[4, 3].NewColor = Color.Black;
            colours[4, 4] = new ColorMap();
            colours[4, 4].OldColor = Color.Gray;
            colours[4, 4].NewColor = Color.Black;
            return colours;
        }

        #endregion
    }

    public class StockpileGraphic : Graphic
    {
        #region Variables
        private Stockpile _type;
        #endregion

        #region Constructor
        public StockpileGraphic(Point point, Size size, Stockpile type)
            : base(point, size)
        {
            _type = type;
        }
        #endregion

        #region Factory Method
        // Will eventually also handle tooltips (hence the factory method).
        public static StockpileGraphic Create(Point point, Size size, Stockpile type)
        {
            return new StockpileGraphic(point, size, type);
        }
        #endregion

        #region Graphic members
        public override Bitmap GetBitmap()
        {
            Bitmap bitmap = new Bitmap(_size.Width * _tileset.GridWidth, _size.Height * _tileset.GridHeight);

            Bitmap tile = new Bitmap(_tileset.GridWidth, _tileset.GridHeight);
            ColorMap[] colourMap = new ColorMap[2];
            colourMap[0] = new ColorMap();
            colourMap[0].OldColor = Color.Magenta;
            colourMap[0].NewColor = Color.Black;
            colourMap[1] = new ColorMap();
            colourMap[1].OldColor = Color.White;
            colourMap[1].NewColor = Color.Gray;
            ImageAttributes attrs = new ImageAttributes();
            attrs.SetRemapTable(colourMap);
            Graphics gTile = Graphics.FromImage(tile);
            gTile.DrawImage(_tileset.Bitmap, new Rectangle(0, 0, _tileset.GridWidth, _tileset.GridHeight), 13 * _tileset.GridWidth, 3 * _tileset.GridHeight, _tileset.GridWidth, _tileset.GridHeight, GraphicsUnit.Pixel, attrs);

            Graphics gBitmap = Graphics.FromImage(bitmap);
            for (int y = 0; y < _size.Height; y++)
            {
                for (int x = 0; x < _size.Width; x++)
                {
                    gBitmap.DrawImage(tile, new Point(x * _tileset.GridWidth, y * _tileset.GridHeight));
                }
            }

            return bitmap;

        }
        #endregion
    }
}
